#include "graphics/text.h"

#include "system/window.h"
#include <SDL/SDL_ttf.h>

EsdlFont* esdlLoadTextFont(const char* fontName, int fontSize, int fontStyle) {
	EsdlFont* font = NULL;
	font = TTF_OpenFont(fontName, fontSize);
	if(!font)	return NULL;
	TTF_SetFontStyle(font, fontStyle);
	return font;
}

void esdlCloseTextFont(EsdlFont* font) {
	TTF_CloseFont(font);
}

void esdlDrawText(EsdlSprite* sprite, const char* text, int x, int y, EsdlFont* font, EsdlColor color) {
    SDL_Surface* surface = TTF_RenderText_Solid(font, text, color);

    SDL_Rect rect;
    rect.x = x;
    rect.y = y;
    rect.w = surface->w;
    rect.h = surface->h;
    SDL_BlitSurface(surface, NULL, sprite->surface, &rect);
}

void esdlDrawAntiAliasedText(EsdlSprite* sprite, const char* text, int x, int y, EsdlFont* font, EsdlColor color) {
    SDL_Surface* surface = TTF_RenderText_Blended(font, text, color);

    SDL_Rect rect;
    rect.x = x;
    rect.y = y;
    rect.w = surface->w-x;
    rect.h = surface->h-y;
    SDL_BlitSurface(surface, NULL, sprite->surface, &rect);
}

